package com.cgx.tablet.beeper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cgx.tablet.beeper.R;
import com.cgx.tablet.beeper.bean.AbandonCallBean;
import com.cgx.tablet.beeper.interfaces.OnItemClickListener;
import com.yatoooon.screenadaptation.ScreenAdapterTools;

/**
 * Created by Administrator on 2018/9/5 0005.
 */

public class AbandonCallAdapter extends BaseAdapter<AbandonCallBean> {

    private Context mContext;
    LayoutInflater mInflater;
    private OnItemClickListener onItemClickListener;

    public AbandonCallAdapter(Context context) {
        mContext = context;
        this.mInflater = LayoutInflater.from(this.mContext);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    protected View newView(Context context, int position, ViewGroup viewGroup) {
        View view = mInflater.inflate(R.layout.item_abandon_call, null);

        AbandonCallAdapter.ViewHolder holder = new AbandonCallAdapter.ViewHolder();
        holder.ticket = view.findViewById(R.id.ticket);
        holder.deal_win = view.findViewById(R.id.deal_win);
        holder.finish_time = view.findViewById(R.id.finish_time);
        holder.operate = view.findViewById(R.id.discarded_recall_operate);
        view.setTag(holder);
        ScreenAdapterTools.getInstance().loadView(view);
        return view;
    }

    @Override
    protected void bindView(View view, final int position, AbandonCallBean abandonCallBean) {
        AbandonCallAdapter.ViewHolder holder = (ViewHolder) view.getTag();
        if (abandonCallBean != null){
            holder.ticket.setText(abandonCallBean.getTicket());
            holder.deal_win.setText("窗口" + abandonCallBean.getDealWin());
            holder.finish_time.setText(abandonCallBean.getFinishTime());
            holder.operate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClickListener != null)
                        onItemClickListener.onItemClick(v, position);
                }
            });
        }
    }

    @Override
    public long getItemId(int position) {
        AbandonCallBean abandonCallBean = this.getItem(position);
        return abandonCallBean == null ? 0L:(long)abandonCallBean.hashCode();
    }

    private static class ViewHolder {
        TextView ticket;
        TextView deal_win;
        TextView finish_time;
        TextView operate;
    }

}
